package com.wdc.n1;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class SaleTicketDemo01 {



    public static void main(String[] args) {

        Ticket2 ticket2 = new Ticket2();

        ConcurrentHashMap<String, String> stringStringConcurrentHashMap = new ConcurrentHashMap<>();
         Map<Object, Object> objectObjectHashMap = new HashMap<>();
        HashMap<Object, Object> objectObjectHashMap1 = new HashMap<>(objectObjectHashMap);

        Map<String, String> stringStringMap = Collections.synchronizedMap(new HashMap<String, String>());


        new Thread(() -> {
            for (int i = 0; i < 40; i++) {
                ticket2.sale();
            }

        }, "A").start();

        new Thread(() -> {
            for (int i = 0; i < 40; i++) {
                ticket2.sale();
            }

        }, "B").start();

        new Thread(() -> {
            for (int i = 0; i < 40; i++) {
                ticket2.sale();
            }

        }, "C").start();
    }



}

class Ticket {
    private int number = 30;

    public synchronized void sale() {
        if (number > 0) {
            System.out.println(Thread.currentThread().getName() + " 卖出了第 " + number-- + " 票，剩余" + number);

        }
    }
}